// os_feature_enabled_simple()
#include <os/feature_private.h>
#include "objc-private.h"
#include "objc-loadmethod.h"
#include "objc-file.h"
#include "message.h"

/**********************************************************************
* Associative Reference Support
**********************************************************************/

/**
 * 从源对象取出关联对象值
 * Parameter @object: 关联的源对象
 * Parameter @key:    关联键
 */
id
objc_getAssociatedObject(id object, const void *key)
{
    return _object_get_associative_reference(object, key);
}

typedef void (*objc_hook_setAssociatedObject)(id _Nonnull object, const void * _Nonnull key,
                                              id _Nullable value, objc_AssociationPolicy policy);

void
objc_setHook_setAssociatedObject(objc_hook_setAssociatedObject _Nonnull newValue,
                                 objc_hook_setAssociatedObject _Nullable * _Nonnull outOldValue) {
  // See objc_object::setHasAssociatedObjects() for a replacement
}

/**
 * 关联对象
 * Parameter @object: 关联的源对象
 * Parameter @key:    关联键
 * Parameter @value:  关联值
 * Parameter @policy: 策略
 */
void
objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
{
    _object_set_associative_reference(object, key, value, policy);
}

/* 移除 源对象 的 关联
 * Parameter @object: 关联的源对象
 */
void objc_removeAssociatedObjects(id object) 
{
    if (object && object->hasAssociatedObjects()) {
        _object_remove_assocations(object, /*deallocating*/false);
    }
}
